package com.goktech.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @ClassName SqlSessionUtil
 * @Description TODO
 * @Author 邱华英
 * @Date 2022/10/3 10:54
 * @Version 1.0
 */

public class SqlSessionUtil {

    public static SqlSession getSqlSession(){
        try {
            InputStream resourceAsStream = Resources.getResourceAsStream("mybatisConfig.xml");
            SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
            SqlSession sqlSession = sqlSessionFactoryBuilder.build(resourceAsStream).openSession(true);
            return sqlSession;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
